package day1;

import java.util.Random;

public class Demo1 {
    public static void main(String[] args) {
        Random rd = new Random();
        char a = RandomEnglish();
        System.out.println(a);
        int b = RandomNum();
        System.out.println(b);
        String c = RandomSex();
        System.out.println(c);

        //初始化student
        Student[] student = new Student[100];
        int male =0;
        int small =0;
        int middle = 0;
        int old = 0;
        for(int i = 0 ; i < 100 ; i++){
            student[i] = new Student();
            student[i].setName(name());
            student[i].setSex(RandomSex());
            if(i<50) student[i].setAge(rd.nextInt(5)+20);
            else if(i>=50&&i<70) student[i].setAge(rd.nextInt(2)+18);
            else if(i<100) student[i].setAge(rd.nextInt(40)+25);
            if(student[i].getSex()=="male") male++;
            if(student[i].getAge()>=18&&student[i].getAge()<20) small++;
            else if(student[i].getAge()>=20&&student[i].getAge()<25) middle++;
            else old++;
            System.out.println(student[i].getName()+" "+student[i].getSex()+" "+student[i].getAge());
        }
        System.out.println("男女比例為"+male/(100-male));
        System.out.println("男有"+male+"人，女有"+(100-male)+"人");
        System.out.println("18-20有"+small);
        System.out.println("20-25有"+middle);
        System.out.println("其他有"+old);

    }

    //随机生成4个英文单词的名字
    public static String name(){
        String a;
        a = Integer.toString(RandomEnglish(),RandomEnglish());
        String b = a+RandomEnglish();
        String c = b+RandomEnglish();
        return c;
    }

    //随机生成性别字符串(male/female)
    public static String RandomSex(){
        String[] sex = {"male","famale"};
        Random rd = new Random();
        int i = rd.nextInt(2);
        return sex[i];
    }

    //随机生成1-100的整数
    public static int RandomNum(){
        Random rd = new Random();
        int num = rd.nextInt(100);
        return num;
    }
    //随机生成A-Z a-z
        public static char RandomEnglish() {
            Random rd = new Random();
            char[] chars = new char[52];
            char count = 65;
            char count1 = 97;
            for (int i = 0; i < 52; i++) {
                if (i < 26) {
                    chars[i] = count;
                    count++;
                } else {
                    chars[i] = count1;
                    count1++;
                }
            }
            return chars[rd.nextInt(52)];
    }

}
class Student{
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    private String sex;
    private int age;
}


